<?php
# idxCMS Flat Files Content Management System v5.0
# Copyright (c) 2011-2016 Victor Nabatov greenray.spb@gmail.com
# Module USER: User panel

if (!defined('idxCMS')) die();

$info = ['', ''];

if (USER::$logged_in) {
    $PM   = new MESSAGE(PM_DATA, USER::getUser('user'));
    $info = $PM->checkNewMessages();
    unset($PM);
}

$files = AdvScanDir(SKINS, '', 'dir', FALSE, ['images']);
$skins = [];
foreach($files as $key => $name) {
    $skins[$key]['name'] = $name;
    if ($name === SYSTEM::get('skin')) {
        $skins[$key]['selected'] = TRUE;
    }
}

$files     = SYSTEM::get('languages');
$languages = [];
foreach($files as $key => $language) {
    $languages[$key]['name'] = $language;
    if ($language === SYSTEM::get('language')) {
        $languages[$key]['selected'] = TRUE;
    }
}

$TEMPLATE = new TEMPLATE(__DIR__.DS.'panel');
$TEMPLATE->set('logged_in',      USER::$logged_in);
$TEMPLATE->set('user',           USER::getUser('nick'));
$TEMPLATE->set('admin',          USER::$root);
$TEMPLATE->set('mess_new',       $info[0]);
$TEMPLATE->set('mess_info',      $info[1]);
$TEMPLATE->set('captcha',        ShowCaptcha());
$TEMPLATE->set('allow_skin',     CONFIG::getValue('main', 'allow_skin'));
$TEMPLATE->set('skin',           $skins);
$TEMPLATE->set('allow_language', CONFIG::getValue('main', 'allow_language'));
$TEMPLATE->set('language',       $languages);

SYSTEM::defineWindow('User panel', $TEMPLATE->parse());
